package com.example.iotmanagerment26.service.impl;

import com.example.iotmanagerment26.domain.User;
import com.example.iotmanagerment26.domain.vo.UserCard;
import com.example.iotmanagerment26.domain.vo.UserOprecordVO;
import com.example.iotmanagerment26.mapper.UserMapper;
import com.example.iotmanagerment26.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public User selectUserByName(String userName) {
        return userMapper.selectUserByName(userName);
    }

    @Override
    public List<User> selectAllUser() {
        return userMapper.selectAllUser();
    }

    @Override
    public int insertUser(User user) {
        User user1 = userMapper.selectUserByName(user.getUsername());
        if (user1!=null) {
            return -1;
        }else {
            return userMapper.insertUser(user);
        }
    }

    @Override
    public int deleteUserById(int id) {
        return userMapper.deleteUserById(id);
    }

    @Override
    public int updatePasswordByName(String name, String password) {
        return userMapper.updatePasswordByName(name,password);
    }

    @Override
    public User login(User user) {
        return userMapper.login(user);
    }

    @Override
    public UserCard selectUserWithCardById(int id) {
        return userMapper.selectUserWithCardById(id);
    }

    @Override
    public List<UserCard> selectAllUserWithCard() {
        return userMapper.selectAllUserWithCard();
    }

    @Override
    public UserOprecordVO selectUserOprecordsById(int id) {
        return userMapper.selectUserOprecordsById(id);
    }

    @Override
    public List<User> selectAllUserByPower(String power) {
        return  userMapper.selectAllUserByPower(power);
    }
}
